cc.Class({
  extends: cc.Component,
  properties: {
    uidLabel: cc.Label,
    root1: cc.Node,
    root2: cc.Node,
    rewardNode: cc.Node,
    wxNode: cc.Node
  },
  initBy: function (e) {
    var t = this;
    this.onCloseCB = e;
    this.preAuth = cc.player.auth;
    this.uidLabel.string = cc.pvz.cloud.uid;
    this.root1.active = false;
    this.root2.active = false;
    this.rewardNode.active = 1 != cc.player.auth;
    if (cc.sys.platform == cc.sys.WECHAT_GAME) {
      wx.getSetting({
        success: function (e) {
          if (true === e.authSetting["scope.userInfo"]) {
            t.root2.active = true;
          } else {
            t.root1.active = true;
          }
        }
      });
    } else {
      this.root1.active = this.rewardNode.active;
      this.root2.active = !this.rewardNode.active;
    }
  },
  onClickClose: function () {
    this.wxNode.destroy();
    cc.popupManager.removePopup(this);
    this.onCloseCB && this.onCloseCB(1 != this.preAuth && 1 == cc.player.auth);
  },
  onAuthorizeSucc: function () {
    this.root1.active = false;
    this.root2.active = true;
    this.rewardNode.active = false;
    if (1 != cc.player.auth) {
      cc.player.auth = 1;
      var e = cc.pvz.GameConfig.ItemType.钻石;
      cc.pvz.PlayerData.changeItemNum(e, 100);
      cc.popupManager.showEffectFly(e, cc.MainControl.getItemEffectPos(e), cc.math.randomRangeInt(1, 4));
      cc.MainControl.updateItemInfo();
    }
  },
  onWxAuthorize: function (e) {
    var t = this;
    console.log("xxxxxxxxxxxxxxxxxxxxxxxxx");
    console.log(e);
    e.userInfo && e.userInfo.avatarUrl && e.userInfo.nickName && cc.pvz.cloud.setAvatar(e.userInfo.nickName, e.userInfo.avatarUrl, function (e) {
      if (e) {
        t.onAuthorizeSucc();
      } else {
        cc.popupManager.showToast("授权失败,稍后再试");
      }
    });
  }
});